# -*- coding: utf-8 -*-
"""
Created on Thu May 16 20:02:22 2019

@author: yaoyu
"""

import tushare as ts
import numpy as np
#import pandas as pd

df = ts.get_hist_data('300021', start='2019-01-01', end='2019-05-16')
df = df.iloc[:, :5] # 获取前 5 列
df.sort_index(inplace = True) # 按 date 列进行排序

min_day = df.sort_values('volume').iloc[0,]
min_volume = min_day.volume
min_volume_date = min_day.name
print("the min volume of {} is at {}".format(min_volume, min_volume_date))

max_day = df.sort_values('volume').iloc[-1,]
max_volume = max_day.volume
max_volume_date = max_day.name
print("the max volume of {} is at {}".format(max_volume, max_volume_date))

# 3
print(df[df.volume >= 1000000])
# 4
print(len(df[df.close > df.open]))
# 5
print(df.open.diff())
print(np.sign(np.diff(df.open)))
# 6
month = [item[5:7] for item in df.index]
print(df.close.groupby(month).apply(np.mean))